package com.web.webrecive.mq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.web.webrecive.pojo.AuthUser;
import com.web.webrecive.service.AuthUserService;
import com.web.webrecive.utils.KeyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * Created with IDEA
 * author:HanLiBin
 * Date:2018/3/2
 * Time:14:45
 * version 1.0
 */
@Component
public class MsgReceive {
    @Autowired
    private AuthUserService authUserService;
    @JmsListener(destination = "my_destination")
    public void receiveMessage(byte [] message){
        byte[] data= null;
        try {
            data = KeyUtils.decryptByPrivateKey(message);
            String dataJson=new String(data);
            AuthUser authUser= JSON.parseObject(dataJson, new TypeReference<AuthUser>() {});
            authUserService.create(authUser);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
